package net.hctek.identity.util.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import net.hctek.identity.action.SocketThread;



public class ServerSocketListener implements ServletContextListener{

	private SocketThread socketThread;
	
	@Override
	public void contextDestroyed(ServletContextEvent e) {
		if(socketThread != null && socketThread.isInterrupted()){
			socketThread.closeServerSocket();
			socketThread.interrupt();
		}
	}

	@Override
	public void contextInitialized(ServletContextEvent e) {
		ServletContext servletContext = e.getServletContext();
		if(socketThread == null){
			socketThread = new SocketThread(null,servletContext);
			socketThread.start();
		}
	}

}
